import forumAxios from '../utils/request'

const BASE_URL = '/user'

export async function createUser(user) {
    // console.log(user)
    const resp = await forumAxios.post(BASE_URL + '/createUser', {
        "username": user.username,
        "nickname": user.nickname,
        "password": user.password
    })

    return resp
}

export async function login(user) {
    console.log(user)
    const resp = await forumAxios.post(BASE_URL + '/login', {
        "username": user.username,
        "password": user.password
    })

    return resp
}

export async function getUserInfo() {
    const resp = await forumAxios.get(BASE_URL + '/getUserInfo')
        // console.log(resp)
    return resp
}

export async function logout() {
    const resp = await forumAxios.get(BASE_URL + '/logout')
    return resp
}

export async function getUserInfoByUserId(userId) {
    const resp = await forumAxios.get(BASE_URL + '/getUserInfoByUserId', {
            params: {
                userId: userId
            }
        })
        // console.log(resp)
    return resp
}

export async function updateUserInfo(userInfo) {
    const user = {}
    const field = userInfo.field
    const value = userInfo.value
    user[field] = value
    const resp = await forumAxios.post(BASE_URL + '/updateUser', user);
    return resp
}